<?php
namespace app\mypay\controller;
use think\Controller;
use think\Db;
use think\Loader;
class Wei extends Controller
{
    
    public function _initialize()
    {
        $config = cache('db_config_data');
        if (!$config)
        {
            $config = api('Config/lists');
            cache('db_config_data', $config);
        }
        config($config);
    }
    public function _empty($name)
    {
        return $this->fetch('/Public/404');
    }
      public function newwxzhifu()
    {
        $ip    = getIP();
        check_ts($ip);
     
        $code    = input("code");

		$state   = input("state");
		
	
	    
	
		if(empty($state) || empty($code)){
		    die('参数错误1！');
		}
		
		$order_info = Db::name('order')->where(['orderid' => $state])->find();
		
		if(!$order_info){
		      die('订单存在！');
		}
	
        $zhifu = Db::name("zhifu")->where(['id' => 1])->find();
        $content = unserialize($zhifu['content']);
        
        Loader::import('weixinpay.WxPayPubHelper');
        
        $jsApi = new \JsApi_pub();
       
        $jsApi->setCode($code);
        $openid = $jsApi->getOpenId();
        
        
        
       
        $ename = $content['shename'];
        $url2 = "http://" . $ename . '/mypay/weixinpay/newweixinpay?state=' . $state . "&openid=" . $openid; 
        
        echo  "<script>location.href='$url2'</script>";  
      
    }
   
    
}